package com.alpaca.recommend.mapreduce;

import com.alpaca.recommend.bean.TagItem;
import com.alpaca.recommend.bean.UTags;
import com.alpaca.recommend.hbase.HTableClients;
import com.alpaca.recommend.util.MD5Util;
import org.apache.hadoop.hbase.client.HTableInterface;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Table;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by justin on 15-2-10.
 */
public class initData {

    public static void main(String[] args) throws IOException {
        initTagItemsDATA();

    }

    public static void initTagItemsDATA() throws IOException {
        Table tagItemsTable = new HTableClients().getHTable(TagItem.TABLE_NAME);
        InputStreamReader read = new InputStreamReader(new FileInputStream(new File("/home/justin/tmp-data/tag_items_data")),"UTF-8");
        BufferedReader bufferedReader = new BufferedReader(read);
        String lineText = null;
        List<Put> puts = new ArrayList<Put>();
        while((lineText = bufferedReader.readLine())!= null){
            String[] datas = lineText.split(" ");
            Put put = TagItem.getPut(datas[0],datas[1],datas[2],Integer.valueOf(datas[3]),Integer.valueOf(datas[3]));
            puts.add(put);
        }
        read.close();
        tagItemsTable.put(puts);
        tagItemsTable.close();
    }



    /***
     * 初始化u_tags数据
     * @throws IOException
     */
    public static void initUTAGSDATA() throws IOException {
        Table uTagTable = new HTableClients().getHTable(UTags.TABLE_NAME);
        InputStreamReader read = new InputStreamReader(new FileInputStream(new File("/home/justin/tmp-data/u_tags_data")),"UTF-8");
        BufferedReader bufferedReader = new BufferedReader(read);
        String lineText = null;
        List<Put> puts = new ArrayList<Put>();
        while((lineText = bufferedReader.readLine())!= null){
            String[] datas = lineText.split(" ");
            Put put = UTags.getPut(datas[0],datas[1],datas[2],Integer.valueOf(datas[3]),Integer.valueOf(datas[3]));
            puts.add(put);
        }
        read.close();
        uTagTable.put(puts);
        uTagTable.close();
    }
}
